<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改店铺信息</title>
    <style>
        div {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        table,tr,th,td{
            border: 1px solid #5fbdcb;
        }
        table{
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    请选择你所要修改的信息：
    <label>
        <select id="select">
            <option id="storeName" value="storeName">店铺名</option>
            <option id="introduce" value="introduce">简介</option>
        </select>
    </label><br>
    <label for="value"></label><textarea name="value" id="value" placeholder="请输入新的内容"></textarea><br>
    <button id="button">提交</button>
    <a href="SellerStorePage.jsp">返回</a>
</div>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    function getParam(url, name) {
        try {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = url.split('?')[1].match(reg);
            if (r != null) {
                return r[2];
            }
            return "";
        } catch (e) {
            return "";
        }
    }

    let url = window.location.href;
    let storeId = getParam(url, 'storeId');
    $(function () {
        $(':button').on('click', function () {
            $.ajax({
                url: "http://localhost:8080/store.do",
                type: "post",
                data: {
                    select: $('#select').val(),
                    value: $('#value').val(),
                    storeId: storeId,
                    method: 'modify'
                },
                dataType: "text",
                success: function (data) {
                    if (data === "ok") {
                        alert("修改成功");
                    } else {
                        alert("修改失败，请重新修改");
                    }
                }
            })
        })
    })
</script>
</body>
</html>
